/*
 * p3586.cpp
 *
 *  Created on: 2013-5-20
 *      Author: zy
 */

#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
using namespace std;
const int INF = 0x3f3f3f3f;
const int maxn = 1100;
int dp[maxn];
int dist[maxn][maxn];
int n, m, mid;
vector<int> son[maxn];
void dfs(int s, int pa)
{
	if (dist[s][pa] <= mid)
		dp[s] = dist[s][pa];
	if(son[s].size()==1)return;
	int tem = 0;
	for (int i = 0; i < son[s].size(); i++)
	{
		int v = son[s][i];
		if (v == pa)
			continue;
		dfs(v, s);
		if (dp[v] >= INF)
			tem = INF;
		else
			tem += dp[v];
	}
	dp[s] = min(dp[s], tem);
}
bool check()
{
	memset(dp, 0x3f3f3f3f, sizeof(dp));
	dfs(1, 0);
	if (dp[1] <= m)
		return true;
	return false;
}
int main()
{
	while (scanf("%d%d", &n, &m) && n && m)
	{
		for (int i = 0; i <= n; i++)
			son[i].clear();
		memset(dist, 0x3f3f3f3f, sizeof(dist));
		int maxlen = 0;
		for (int i = 1; i < n; i++)
		{
			int a, b, c;
			scanf("%d%d%d", &a, &b, &c);
			maxlen = max(c, maxlen);
			son[b].push_back(a);
			son[a].push_back(b);
			dist[a][b] = dist[b][a] = c;
		}
		son[1].push_back(0);
		int left = 1, right = maxlen, ans = -1;
		while (left <= right)
		{
			mid = (left + right) / 2;//注意防止L+R溢出
			if (check())
			{
				ans = mid;
				right = mid - 1;
			}
			else
				left = mid + 1;
		}
		printf("%d\n", ans);
	}
	return 0;
}
